//
//  HRZShoppingCartCountView.m
//  EMarket
//
//  Created by 石头 on 2018/10/16.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZShoppingCartCountView.h"

#import "UIButton+SPRelayout.h"

@interface HRZShoppingCartCountView ()

@property (nonatomic, strong) UIButton *mAllSeletedBtn;
@property (nonatomic, strong) UILabel *mTotalPriceLabel;
@property (nonatomic, strong) UIButton *mSettlementBtn;

@end

@implementation HRZShoppingCartCountView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.mAllSeletedBtn];
        [self addSubview:self.mTotalPriceLabel];
        [self addSubview:self.mSettlementBtn];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.mAllSeletedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.left.mas_equalTo(self).mas_offset(10);
        make.height.mas_equalTo(self.height - 10);
//        make.width.mas_equalTo(30);
    }];
    
    [self.mSettlementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).mas_offset(-10);
        make.height.mas_equalTo(self.height - 20);
        make.width.mas_equalTo(80);
    }];
    
    [self.mTotalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self.mSettlementBtn.mas_left).mas_offset(-10);
    }];
}

#pragma mark - ----  EventResponse  ----
- (void)onAllSelectdBtnClick {
    _isAllSelectd = !_isAllSelectd;
    
    [self setAllSelectBtnImage];
    if (_AllClickBlock) {
        _AllClickBlock(_isAllSelectd);
    }
}

- (void)onSettlementBtnClick {
    if (_AccountBlock) {
        _AccountBlock();
    }
}

- (void)setAllSelectBtnImage {
    if (_isAllSelectd) {
        [_mAllSeletedBtn setImage:IMAGE_NAMED(@"clicked") forState:UIControlStateNormal];
    } else {
        [_mAllSeletedBtn setImage:IMAGE_NAMED(@"unClick") forState:UIControlStateNormal];
    }
}

#pragma mark - ----  Getter/Setter  ----
- (UIButton *)mAllSeletedBtn{
    if (!_mAllSeletedBtn) {
        _mAllSeletedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _mAllSeletedBtn.titleLabel.font = PFR13Font;
        [_mAllSeletedBtn setImage:IMAGE_NAMED(@"unClick") forState:UIControlStateNormal];
        [_mAllSeletedBtn setTitle:@"全选" forState:UIControlStateNormal];
        _mAllSeletedBtn.titleLabel.font = PFR15Font;
        [_mAllSeletedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_mAllSeletedBtn addTarget:self action:@selector(onAllSelectdBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _mAllSeletedBtn;
}

- (UIButton *)mSettlementBtn{
    if (!_mSettlementBtn) {
        _mSettlementBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _mSettlementBtn.backgroundColor = [UIColor redColor];
        _mSettlementBtn.titleLabel.font = PFR13Font;
        [_mSettlementBtn setTitle:@"结算" forState:UIControlStateNormal];
        [_mSettlementBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_mSettlementBtn addTarget:self action:@selector(onSettlementBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _mSettlementBtn;
}

- (UILabel *)mTotalPriceLabel{
    if (!_mTotalPriceLabel) {
        _mTotalPriceLabel = [[UILabel alloc] init];
        _mTotalPriceLabel.font = PFR12Font;
    }
    return _mTotalPriceLabel;
}

-(void)setTotalPrice:(NSString *)totalPrice {
    _totalPrice = totalPrice;
    _mTotalPriceLabel.text = [NSString stringWithFormat:@"总价:¥ %@", _totalPrice];
}

- (void)setIsAllSelectd:(BOOL)isAllSelectd {
    _isAllSelectd = isAllSelectd;
    [self setAllSelectBtnImage];
}


@end
